import { createRouter, createWebHashHistory } from "vue-router";
import routes from "./list";

import type { Router } from "vue-router";

const router: Router = createRouter({
  history: createWebHashHistory(),
  routes,
});

router.beforeEach((to, _from, next) => {
  if (
    to.path === "/" ||
    to.path === "/login" ||
    to.path === "/register" ||
    to.path === "/noAuth" ||
    to.path === "/authCompany" ||
    to.path === "/authing" ||
    to.path === "/authingResult" ||
    to.path === "/forgetPassword" ||
    to.path === "/resetSuccess"
  ) {
    next();
  } else {
    if (MyModule.storage.getItem("token", "")) {
      next();
    } else {
      next("/login");
    }
  }
});

export default router;
